import axios from "../request";

interface Info {
  key: string; //资讯编号
  type: string; //资讯类型
  img: string; //图片（一张）
  title: string; //标题
  state: string; // 发布/未发布
  publisher: string; //发布者
  time: string; //发布时间
  origin: string; //资讯来源
  intro: string; //资讯内容
}
// 获取行业资讯总数据-分类有：房产资讯、行业动态、政策解读
const paging = async ({ keyword, $limit = 10, $page = 1 }: any) => {
  // const { keyword, $limit, $page } = params;
  const $skip = ($page - 1) * $limit;
  let queryStr = "";
  if (keyword) queryStr += `$title=${keyword}`;
  const res = await axios.get(
    `/info?$limit=${$limit}&$skip=${$skip}${queryStr}`
  );
  return res;
};
// 房产资讯
const consult = async () => {
  const res = await axios.get("/info/type/consult");
  return res;
};
// 行业动态
const dongtai = async () => {
  const res = await axios.get("/info/type/dongtai");
  return res;
};
// 政策解读
const policy = async () => {
  const res = await axios.get("/info/type/policy");
  return res;
};
// 行业资讯 增
const addinfo = async () => {
  const res = await axios.post("/info/addinfo");
  return res;
};
// 行业资讯 删 需要传_id
const delinfo = async () => {
  const res = await axios.post("/info/del");
  return res;
};
// 行业资讯 改 需要传id
const editinfo = async (data: Info) => {
  const { key, type, img, title, state, publisher, time, origin, intro } = data;
  const res = await axios.post("/info/editinfo", {
    key,
    type,
    img,
    title,
    state,
    publisher,
    time,
    origin,
    intro
  });
  return res;
};

//查
const getEvent = async (id: string | number) => {
  const res = await axios.get(`/info/${id}`);
  return res;
};
export default {
  paging,
  consult,
  dongtai,
  getEvent,
  editinfo,
  delinfo,
  addinfo
};
